<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>7.WeakSet语法介绍</title>
</head>

<body>
  <div></div>
  <div></div>
  <script>
    // WeakSet 操作的必须是对象类型

    // let weakSet= new WeakSet(['hdcms','houdunren']);
    //Invalid value used in weak set
    // 报错,操作的是字符串
    // let weakSet = new WeakSet('ok'); ///Invalid value used in weak set 报错字符串不是对象
    let weakSet = new WeakSet();
    weakSet.add(['hdcms', 'houdunren']); //这样不报错，因为整个数组被作为一个值加入weakSet里面
    let nodes = new WeakSet();
    let divs = document.querySelectorAll('div');
    // 和Set 一样，WeakSet 也不会重复添加元素
    //  add 增加元素
    divs.forEach(item => nodes.add(item));
    console.log(nodes);//WeakSet {div, div
    // delete 移除元素
    nodes.delete(divs[0]);
    console.log(nodes);//WeakSet {div}
    //  has 是否包含元素
    console.log(nodes.has(divs[1]));// true

  </script>
</body>

</html>